package com.sgb.contract.view.widget;

import android.content.Context;

import com.swgk.core.dialog.RoundDialog;

/**
 * 带Tag传递的app统一的Dialog弹窗
 * @author cyj
 */
public class TagBuilder extends RoundDialog.Builder {

    private Object mTag;
    private RoundDialog.SingleCallback listener;

    public TagBuilder(Context context) {
        super(context);
    }

    /**
     * 设置tag
     * @param tag    Object
     * @return       TagBuilder
     */
    public TagBuilder setTag(Object tag) {
        this.mTag = tag;
        return this;
    }

    /**
     * 拦截 RoundDialog.SingleCallback 事件实现tag传递
     * @param callback    RoundDialog.SingleCallback
     * @return            TagBuilder
     */
    @Override
    public RoundDialog.Builder confirmCallback(RoundDialog.SingleCallback callback) {
        this.listener = callback;
        return super.confirmCallback(v -> {
            if(null != listener) {
                v.setTag(mTag);
                listener.onClick(v);
            }
        });
    }
}
